import pandas as pd
import numpy as np
import sqlite3
import json
import redis

# Create your views here.

if __name__ == '__main__':

    db_path = '../db.sqlite3'

else:

    db_path = 'db.sqlite3'

r = redis.Redis(host='192.168.92.132', port=6379, password = '1', db = '0')


class DouBanAna:

    def __init__(self):

        self.conn = sqlite3.connect(db_path)

        sql = 'SELECT * FROM DMSC_csv'

        self.df = pd.read_sql(sql, self.conn)


    def how_many_reviews_are_there_per_movie(self):

        info = self.df.groupby('Movie_Name_CN').count()['index']

        info_dict = info.to_dict()

        r.set('how_many_reviews_are_there_per_movie', json.dumps(info_dict))  

        return info

DouBanAna_obj = DouBanAna()

if __name__ == '__main__':

    x = DouBanAna_obj


    
